<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
        <el-form-item label="日期" prop="dateRange">
          <el-date-picker
            clearable
            v-model="dateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="YYYY-MM-DD"
            />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['business:checkIn:export']"
          >导出</el-button>
        </el-col>
      </el-row>

      <el-table v-loading="loading" :data="aiRequestRecordsList">
<!--        <el-table-column label="日期" align="center" prop="dateTime" />-->
        <el-table-column label="素材分类" align="center" prop="materialType" />
        <el-table-column label="素材名称" align="center" prop="materialName" />
        <el-table-column label="素材照片" align="center" prop="materialImg">
            <template #default="scope">
                <image-preview
                    :src="scope.row.materialImg"
                    style="max-width: 100px; max-height: 100px"
                />
            </template>
        </el-table-column>
        <el-table-column label="生成视频预览量" align="center" prop="previewNum" />
        <el-table-column label="生成次数" align="center" prop="createNum" />
        <el-table-column label="效果下载量" align="center" prop="downloadNum" />
        <el-table-column label="点击门店量" align="center" prop="clickShopNum" />
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
</template>

<script setup name="AiSourceMaterial">
import {getAiMaterialUsageDataListApi} from "@/api/system/aiRequestRecords";

const { proxy } = getCurrentInstance();
const aiRequestRecordsList = ref([]);
const loading = ref(true);
const total = ref(0);
const dateRange = ref([]);
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    startTime: '',
    endTime: '',
  },
});

const { queryParams } = toRefs(data);

function getList() {
  loading.value = true;
  let list = JSON.parse(JSON.stringify(queryParams.value))
  if(dateRange.value && dateRange.value.length>0){
    list.startTime = dateRange.value[0]
    list.endTime = dateRange.value[1]
  }
  getAiMaterialUsageDataListApi(list).then(response => {
    aiRequestRecordsList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}


function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    proxy.resetForm("queryRef");
    dateRange.value = []
    handleQuery();
}

function handleExport() {
  let list = JSON.parse(JSON.stringify(queryParams.value))
  if(dateRange.value && dateRange.value.length>0){
    list.startTime = dateRange.value[0]
    list.endTime = dateRange.value[1]
  }
  proxy.download('business/aiSendRecords/getAiUsageDataListExport', {
    ...list
  }, `aiSourceMaterial_${new Date().getTime()}.xlsx`)
}
getList();

</script>
<style lang="scss" scoped>

</style>
